package com.zq.sql;

import java.sql.*;

/**
 * 复习Jdbc
 */
public class JDBCTest {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        String url = "jdbc:mysql://localhost:3306/zq?serverTimezone=UTC";
        String user = "root";
        String password = "root";
        //获取连接对象
        Connection connection = DriverManager.getConnection(url, user, password);
        //获取语句执行对象
        Statement statement = connection.createStatement();
        //执行Sql语句返回结果集
        ResultSet rs = statement.executeQuery("select * from student3");
        //处理结果集
        while (rs.next()) {
            int id = rs.getInt("id");
            String name = rs.getString("name");
            int age = rs.getInt("age");
            String sex = rs.getString("sex");
            String address = rs.getString("address");
            int math = rs.getInt("math");
            int english = rs.getInt("english");

            System.out.println(id + "\t" + name + "\t" + age + "\t" + sex + "\t" + address + "\t" + math + "\t" + english);
        }
        //释放资源
        rs.close();
        statement.close();
        connection.close();
    }
}
